import * as fs from "node:fs"
import * as path from "node:path"
import { Pixel } from "../hp3-img.js";
import { savePng } from "../hp3-png.js";
import { loadImage } from "../hp3-imp.js";

const inputDir = "E:\\gamedev\\resources\\拼格子塔防\\子弹\\ok-auto";
const outputDir = "E:\\gamedev\\resources\\拼格子塔防\\子弹\\ok-auto-2";

const pattern = /(bullet|moon)-.+-ok\.png/;

if(!fs.existsSync(outputDir)){
    fs.mkdirSync(outputDir);
}

const files = fs.readdirSync(inputDir);
for(const file of files){
    if(file.match(pattern)){
        console.error("开始处理："+file);
        const inputFile = path.join(inputDir, file);
        const outputFile = path.join(outputDir, file);
        const src = await loadImage(inputFile);
        const w = src.width;
        const h = src.height;
        const pixels = new Array<Pixel>(w*h);
        for(let y=0; y<h; y++){
            for(let x=0; x<w; x++){
                pixels[y*w+x] = src.pixels[y*w+w-x-1];
            }
        }
        savePng(w,h,pixels,outputFile);
        console.error("处理完成："+file);
    }
}
